<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Hak_akses extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('login_model','l_db');
		$this->load->model('menu_model','menu_db');
		$this->load->model('ha_model','get_db');
	}

	/**
	 * Index Page for this controller.
	 */
	public function index()
	{
		if($this->session->userdata('username')){
			$header['menu'] = $this->l_db->generate_menu();
			$data['grid'] 	= $this->get_db->get_list()->result_array();
			$this->load->view('header_view',$header);
			$this->load->view('ha_view',$data);
			$this->load->view('footer_view');
		}else{
			$this->session->set_flashdata( 'message', array( 'title' => 'Error', 'content' => 'Please login !', 'type' => 'message' )); 
			redirect();
		}
	}	

	public function edit($id = false)
	{
		if($this->session->userdata('username')){
			$header['menu'] = $this->l_db->generate_menu();
			$data['data'] 	= $this->get_db->get_data($id)->result_array();
			$data['id_lvl'] = $id;
			$this->load->view('header_view',$header);
			$this->load->view('edit_hak_view',$data);
			$this->load->view('footer_view');
		}else{
			$this->session->set_flashdata( 'message', array( 'title' => 'Error', 'content' => 'Please login !', 'type' => 'message' )); 
			redirect();
		}
	}		


	public function save($id = false){
		if($_POST){			
			// Update and add
			if($id){		
				if($this->get_db->do_update($id,$_POST)) $this->session->set_flashdata( 'message', array( 'title' => 'Info', 'content' => 'Berhasil merubah !', 'type' => 'alert alert-success' )); 
				else $this->session->set_flashdata( 'message', array( 'title' => 'Error', 'content' => 'Gagal merubah !', 'type' => 'alert alert-error' )); 
				redirect('hak_akses');
			}
		}else{
			die('No direct access!');
		}
	}
}
